﻿using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using eShop.DataAccess.Entity;

namespace eShop.DataAccess
{
    public partial class ShippingRateDAL : BaseDAL
    {
        public static ShippingRate GetByCountryStateCityWeight(string cityName, string stateName, string countryName, float weight)
        {
            ShippingRate shippingRate = new ShippingRate();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("ShippingRate_Custom_GetByCountryStateCityWeight");
            db.AddInParameter(dbCommand, "CityName", DbType.String, cityName);
            db.AddInParameter(dbCommand, "StateName", DbType.String, stateName);
            db.AddInParameter(dbCommand, "CountryName", DbType.String, countryName);
            db.AddInParameter(dbCommand, "Weight", DbType.Double, weight);
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (!dataReader.Read())
                    return null;
                shippingRate = GetEntityFromReader(dataReader);
            }
            return shippingRate;
        }
    }
}

